package com.example.e_comm.dto;

import lombok.Data;

@Data
public class CreateUserRequest {

    private String username;

    private String password;

    private String email;

    private Integer status = 1; // 默认启用状态

    // 手动添加验证方法
    public boolean isValid() {
        return username != null && !username.trim().isEmpty() &&
               password != null && password.length() >= 6 &&
               email != null && !email.trim().isEmpty() && email.contains("@");
    }

    // 获取验证错误信息
    public String getValidationError() {
        if (username == null || username.trim().isEmpty()) {
            return "用户名不能为空";
        }
        if (username.length() < 3 || username.length() > 20) {
            return "用户名长度必须在3-20个字符之间";
        }
        if (password == null) {
            return "密码不能为空";
        }
        if (password.length() < 6 || password.length() > 20) {
            return "密码长度必须在6-20个字符之间";
        }
        if (email == null || email.trim().isEmpty()) {
            return "邮箱不能为空";
        }
        if (!email.contains("@") || !email.contains(".")) {
            return "邮箱格式不正确";
        }
        return null;
    }
}


